# -*- coding: utf-8 -*-
from .base import BaseTool
from .base import PrintUtils,CmdTask,FileUtils,AptUtils,ChooseTask
from .base import osversion,osarch
from .base import run_tool_file

class Tool(BaseTool):
    def __init__(self):
        self.type = BaseTool.TYPE_CONFIG
        self.name = "一键安装opencv"
        self.autor = 'hyw666'

    def install_opencv(self):
        CmdTask("sudo apt update", 0).run()
        CmdTask("sudo apt -y install python3 python3-pip", 0).run()
        CmdTask("sudo ln -sf /usr/bin/python3 /usr/bin/python", 0).run()
        CmdTask("sudo ln -sf /usr/bin/pip3 /usr/bin/pip", 0).run()
        CmdTask("python -m pip install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip", 0).run()
        CmdTask("pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple", 0).run()
        CmdTask("sudo apt -y install python3-pil python3-numpy git wget", 0).run()
        CmdTask("sudo apt -y install libavcodec-dev libavformat-dev libswscale-dev", 0).run()
        CmdTask("sudo apt -y install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev", 0).run()
        if osarch=="arm64":
            CmdTask("pip3 install opencv-python==4.7.0.68", 0).run()
            CmdTask("sudo pip3 install opencv-python==4.7.0.68", 0).run()
        else:
            CmdTask("sudo apt install -y python3-opencv", 0).run()



    def run(self):
        #正式的运行
        self.install_opencv()
